package com.icode.jqgrid;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ZhongGang
 * Date: 14-9-8
 * Time: 下午9:49
 */
public class ResultSet {
    private Integer total;
    private Integer pages;
    private Integer pageSize = 10;
    private Integer currentPage = 0;
    private List<Person> results = new ArrayList<>();

    public Integer getTotal() {
        return results.size();
    }

    public Integer getPages() {
        return getTotal() % pageSize == 0 ? getTotal() / pageSize : getTotal() / pageSize + 1;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public List<Person> getResults() {
        if (this.results.isEmpty()) {
            return this.results;
        }
        List<Person> results = new ArrayList<>();
        int start = (getCurrentPage() - 1) * getPageSize();
        for (int i = start; i < start + getPageSize() && i < this.results.size(); i++) {
            results.add(this.results.get(i));
        }
        return results;
    }

    public void setResults(List<Person> results) {
        this.results = results;
    }
}
